import React from 'react';
import { connect } from 'dva';
import { Link, routerRedux } from 'dva/router';
import { WingBlank, WhiteSpace, Flex, Card, List, Result, Modal } from 'antd-mobile';
import MemberInfo from 'components/MemberInfo';
import styles from './styles.less';
import * as services from 'services/scale';
import BigImg from 'components/scale/bigimg';
import { GENDER_MAP, sheetType} from 'const';
//准备加二维码放大功能
const { Item, Item: { Brief } } = List;
const ScaleRecordDetailPage = ({ dispatch, location, detail, records, ...rest, mypathname, }) => {
  const { record } = location.state;
  let recordDetailuid = "";
  if(detail){
     for (let i = 0; i < records.length; i++) {
        if(records[i].evaUid == detail.uid){
          recordDetailuid = records[i].uid;
        }
     }
  }

  let flag = false;
  let recordEva = record.eva;
  if(recordEva  == 1) {
     mypathname = location.pathname+"/sheet";
  }else if(recordEva  == 2) {
     mypathname = location.pathname+"/sheet";
  }else if(recordEva == 3) {
     mypathname = location.pathname+"/sheet/phy";
  }else if(recordEva == 4) {
     mypathname = location.pathname+"/sheet/pre";
  }else if(recordEva == 5) {
     mypathname = location.pathname+"/sheet/hyp";
  }else if(recordEva == 6) {
     mypathname = location.pathname+"/sheet/chd";
  }else if(recordEva == 11) {
     mypathname = location.pathname+"/sheet/dia";
  }else if(recordEva == 12) {
     mypathname = location.pathname+"/sheet/tcm";
  }else if(recordEva == 13) {
     mypathname = location.pathname+"/sheet/partum"
  }else if(recordEva == 14) {
     mypathname = location.pathname+"/sheet/prepre";
  }else if(recordEva == 16) {
     mypathname = location.pathname+"/sheet/normal";
  }else if(recordEva == 17) {
    mypathname = location.pathname+"/sheet/phy2";
  }

  const delScale = () => {
    Modal.alert('提示', '确定删除该条纪录？', [
      { text: '取消', onPress() { } },
      { text: '确定', onPress: () => {
        if(recordDetailuid !=""){
          dispatch({
            type: 'scale/deleteScaleRecord',
            payload: recordDetailuid,
          });
          dispatch(
              routerRedux.replace({
                 pathname: `/healthy/scale_record`,
            })
          );
        }
        services.queryScaleList().then(n =>{
          dispatch({ type: 'save', payload: { records: n.data || [] } })
       })
      } }
    ]);
  };
  const bigimg = () => {
    flag = true;
    
  }



  return (
    <div>
      <MemberInfo {...record} extra={
        <button
          type="button"
          onClick={delScale}>删除
        </button>
      }/>
      <WhiteSpace size="md" />
      <WingBlank size="md">
        <Card className="record-card">
          <Card.Header
            title={[
              <img src={require('assets/icons/icon-healthy.svg')} key="icon" />,
              record.title
            ]}
            extra={record.createTime} />
          <Card.Body style={{paddingLeft: "0px",paddingRight: "0px"}}>
            <img
              className={styles.qrcode}
              src={detail.qrCode  || detail.qrcode || 'http://placehold.it/640?text=二维码'} style={{width: "100%"}}/>
            <Flex justify="center">
              <h3 className={styles.code}>
                
                { detail.code}
              </h3>
            </Flex>
          </Card.Body>
        </Card>
        <WhiteSpace size="md" />
        <Link to={{
          // pathname: `${location.pathname}/sheet`,
          pathname: mypathname,
          state: { title: record.title, record ,gender: record.gender, step:1},
        }}>
          <List>
            <Item
              arrow="horizontal">
              {"测评详情"}
            </Item>
          </List>
        </Link>
        <WhiteSpace size="lg" />
        <Flex justify="center" style={{
          color: '#aa4929',
        }}><Link to={{
           pathname:"/healthy/scale_record",
        }}>{record.text}</Link></Flex>
        <WhiteSpace size="lg" />
        <Flex justify="center" style={{
          color: '#aa4929',
        }}>请到所属医院获取详细报告及调养方案</Flex>
        <WhiteSpace size="xl" />
      </WingBlank>
    </div>
  );
};

export default connect(({ scale }) => ({
  ...scale,
}))(ScaleRecordDetailPage);
